/*
* Copyright 2010 Competentum group
*
* Licensed under the GNU General Public License, Version 3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.gnu.org/licenses/gpl.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.competentum.windows
{
	import com.competentum.engines.EmployeesEngine;
	import com.competentum.ui.EasyWorkloadWindow;

	public class ScopesManager
	{
		private static var _currentScope:Scope;
		private static var scopes:Vector.<Scope> = new Vector.<Scope>();
		
		public static function get currentScope():Scope
		{
			return _currentScope;
		}
		public static function set currentScope(value:Scope):void
		{
			_currentScope = value;
		}
		
		public static function get currentWindow():EasyWorkloadWindow
		{
			if (!_currentScope)
			{
				return null;
			}
			return _currentScope.window;
		}
		
		public static function addScope(window:EasyWorkloadWindow):void
		{
			var scope:Scope = new Scope(window);
			scope.id = scopes.length;
			window.scope = scope;
			scopes.push(scope);
			currentScope = scope;
		}
		
		public static function terminateCurrentScope():void
		{
			var index:int = -1;
			for (var i:int = 0; i < scopes.length; i ++ )
			{
				if (scopes[i] == currentScope)
				{
					index = i;
					break;
				}
			}
			scopes.splice(index, 1);
		}
	}
}